package at.fhooe.im440.pandora.graphics;

import java.awt.Graphics2D;

import at.fhooe.im440.pandora.core.Core;
import at.fhooe.im440.pandora.io.InputManager;

public class GraphicsSystem {

	private RenderSystem renderSystem;
	private Core core;
	
	private int width;
	private int height;
	
	public GraphicsSystem(Core core) {
		this.core = core;
		renderSystem = new RenderSystem();
	}
	
	public void addInputManager (InputManager i){
		renderSystem.addKeyListener(i);
	}
	
	public void open(int width, int height, boolean fullscreen) {
		this.width = width;
		this.height = height;
		renderSystem.open(core, width, height, fullscreen);
	}
	
	public void render() {
		Graphics2D g = renderSystem.beginUpdate();
		g.clearRect(-width/2, -height/2, width, height);
		core.updateManager.UpdateAll();
		
		core.hudManager.updateAllHUDS();
		core.hudManager.renderAllHUDS(g);
		
		core.entityManager.updateAllEntities();
		core.entityManager.renderAllEntities(g);

		renderSystem.endUpdate();
	}
	
	public void setFrameRate(int fps) {
		renderSystem.setFrameRate(fps);
	}

	public void close() {
		renderSystem.close();
	}

}
